from flask import Flask, request, jsonify

from hiPot.index import check_pdf_in_subdirs_N

app = Flask(__name__)


@app.route('/check', methods=['POST'])
def check_pdf():
    base_path = r'\\ancsrv0006\Report'
    # 获取POST请求的JSON数据
    data = request.json
    data_directory = base_path + '\\' + data.get('dataDirectory')
    pdf_filename = data.get('pdfFilename')
    # 检查参数是否齐全
    if not data_directory or not pdf_filename:
        return jsonify({"error": "Missing data_directory or pdf_filename"}), 400
    # 检查文件是否存在
    file_exists = check_pdf_in_subdirs_N(data_directory, pdf_filename)
    # 返回结果
    return jsonify({"status": file_exists})


if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=9001)
